<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Configuration extends CI_Controller {
 	public function __construct()
    {
        parent::__construct();
        session_start();
        //$this->output->enable_profiler(FALSE);
    	if (!isset($_SESSION['uid']) || $_SESSION['uid'] < 1){
	    	redirect('cmladministration','refresh');
	    }
        $this->load->model('MSetting');
    }
	    
	public function index()
	{
	    //if($_SESSION['role_id'] != 1)
//        {
//            redirect('cmladmin/accessdenied','refresh');
//        }
		$data['title'] = "Global Configuration Setting";
        $data['language_title'] = "Language Setting";
        $data['account_title'] = "Account Setting";
		$data['main'] = 'admin/configuration';
        $data['languages'] = $this->MSetting->getLanguages();
        $data['user'] = $this->MUser->getUserById($_SESSION['uid']);
		$this->load->vars($data);
		$this->load->view('admin/layout'); 
	}
    
    public function accountEdit()
    {
        if($this->input->post('username'))
        {
            $this->MUser->addEditUser($_SESSION['uid']);
	  		$this->session->set_flashdata('message','Account changed');
            redirect('configuration','refresh');
        }
        redirect('configuration','refresh');
    }
    
    public function languageEdit()
	{
        $this->MSetting->updateLanguageByCode($this->input->post('code'));
    	$this->session->set_flashdata('message','Language changed');
    	redirect('configuration','refresh');
	}
    
    public function pageDelete($page_id = 0)
	{
	   $this->MPage->deletePage($page_id);
	   $this->session->set_flashdata('message','Page deleted');
	   redirect('pagelist','refresh');
    }
}
